<?php

namespace app\admin\model\vppz;

use think\Model;
use traits\model\SoftDelete;

class Hospital extends Model
{

    use SoftDelete;



    // 表名
    protected $name = 'vppz_hospital';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'local_text',
		'avatar_url',	// 需在此处追加属性，才会触发获取器 getPicImageUrlAttr
        'rank_text',
        'label_text'
    ];

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    public function area()
    {
        return $this->belongsTo('Area', 'area_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function getLocalTextAttr($value,$data){
        $value = $value ? $value : (isset($data['is_local']) ? $data['is_local'] : '');
        $list = ['1'=>'本地医疗','2'=>'普通医疗'];
        return isset($list[$value]) ? $list[$value] : '';
    }
	// 获取器直接转换url
	public function getAvatarUrlAttr($value,$data)
    {
        return \addons\vppz\library\Vpower::dourl($data['avatar']);
    }
      public function getRankTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['rank']) ? $data['rank'] : '');
        $config = \think\App::initCommon();
        $list = $config['hospital_level'];
        return isset($list[$value]) ? $list[$value] : '';
    }
      public function getLabelTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['label']) ? $data['label'] : '');
        $config = \think\App::initCommon();
        $list = $config['hospital_label'];
        return isset($list[$value]) ? $list[$value] : '';
    }
}
